/**
 * 
 */
package com.softwareinlife.xmpp.server.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.xmpp.JID;

/**
 * @author jangsunjin
 * 
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MessageModel implements Serializable {

	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Message ID
	 */
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private String messageID = null;

	/**
	 * From JID
	 */
	@Persistent
	private String fromJID = null;

	/**
	 * To JID
	 */
	@Persistent
	private String toJID = null;

	/**
	 * Date
	 */
	@Persistent
	private Date date = null;

	/**
	 * Message
	 */
	@Persistent
	private String message = null;

	/**
	 * Constructor
	 * 
	 * @param fromJID
	 * @param toJID
	 * @param message
	 */
	public MessageModel(String fromJID, String toJID, String message) {
		super();

		this.fromJID = fromJID;
		this.toJID = toJID;
		this.message = message;
		this.date = new Date();

		this.messageID = "{" + fromJID + "}{" + toJID + "}{" + message + "}";
	}

	/**
	 * Constructor
	 * 
	 * @param fromJID
	 * @param toJID
	 * @param message
	 */
	public MessageModel(JID fromJID, String toJID, String message) {
		this.fromJID = fromJID.getId();
		this.toJID = toJID;
		this.message = message;
		this.date = new Date();

		this.messageID = "{" + fromJID + "}{" + toJID + "}{" + message + "}";
	}

	/**
	 * @return the messageID
	 */
	public String getMessageID() {
		return messageID;
	}

	/**
	 * @param messageID the messageID to set
	 */
	public void setMessageID(String messageID) {
		this.messageID = messageID;
	}

	/**
	 * @return the fromJID
	 */
	public String getFromJID() {
		return fromJID;
	}

	/**
	 * @param fromJID the fromJID to set
	 */
	public void setFromJID(String fromJID) {
		this.fromJID = fromJID;
	}

	/**
	 * @return the toJID
	 */
	public String getToJID() {
		return toJID;
	}

	/**
	 * @param toJID the toJID to set
	 */
	public void setToJID(String toJID) {
		this.toJID = toJID;
	}

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "MessageModel [messageID=" + messageID + ", fromJID=" + fromJID
				+ ", toJID=" + toJID + ", date=" + date + ", message="
				+ message + "]";
	}
}
